<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 00:33:05
 * @LastEditTime: 2023-10-26 15:08:41
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: BOM成品工艺
 */

namespace App\Models;

use App\Traits\MaterialTrait;
use App\Traits\AutoCodeTrait;
use App\Traits\CarryTrait;
use App\Traits\CarTrait;

class ProPlan extends BaseModel
    {
    use MaterialTrait;
    use AutoCodeTrait;
    use CarryTrait;
    use CarTrait;
    public $timestamps = true;

    public $table = "sys_pro_plan";

    //搬运等  需要记录的数量
    private $quantityField = 'plan_quantity';
    private $auxiliary_quantity_field = 'plan_auxiliary_quantity';
    public $sourceCodeField = "倒毛计划";
    protected $guarded = [];

    public function getSourceAddr()
        {
        return "染厂";
        }
    //运输派车目的地址
    public function getTargetAddr()
        {
        return $this->outfactory->name;
        }

    public function status()
        {
        return $this->belongsTo(Dic::class, "status_id", "key")->where(function ($q)
            {
            $q->where("code", 'table_status');
            });
        }
    public function _creating($model)
        {
        $model->color_material_code = $model->color_id . "_" . $model->material_id;
        }
    public function pro_pot()
        {
        return $this->belongsTo(ProPot::class);
        }
    public function loom()
        {
        return $this->belongsTo(Loom::class);
        }
    public function process_route()
        {
        return $this->belongsTo(ProProcessRoute::class);
        }
    public function order()
        {
        return $this->belongsTo(MarketOrderDetails::class);
        }
    public function pro_storage()
        {
        return $this->hasMany(ProPlanStorage::class, "pro_plan_id");
        }
    public function pro_yarn()
        {
        return $this->hasOne(MpcProYarn::class, "pro_plan_id");
        }
    public function emergency()
        {
        return $this->belongsTo(Dic::class, "emergency_id", "key")->where(function ($q)
            {
            $q->where("code", 'Emergency');
            });
        }
    public function process_pass()
        {
        return $this->hasMany(ProProcessesPass::class, "pro_plan_id");
        }
    public function pass()
        {
        return $this->belongsTo(ProProcessesPass::class);
        }
    public function process()
        {
        return $this->belongsTo(ProProcesses::class);
        }
    public function order_main()
        {
        return $this->belongsTo(MarketOrder::class, "order_code", 'code');
        }
    public function location()
        {
        return $this->belongsTo(MpcLocation::class);
        }
    public function outfactory()
        {
        return $this->belongsTo(Company::class);
        }

    public function department()
        {
        return $this->belongsTo(Department::class);
        }

    }
